package com.ruoyi.web.controller.miniapp;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.miniapp.domain.MiniChildInfo;
import com.ruoyi.miniapp.service.IMiniChildInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 孩子信息Controller
 * 
 * @author duantao
 * @date 2025-09-19
 */
@RestController
@RequestMapping("/miniapp/childInfo")
public class MiniChildInfoController extends BaseController
{
    @Autowired
    private IMiniChildInfoService miniChildInfoService;

    /**
     * 查询孩子信息列表
     */
    @PreAuthorize("@ss.hasPermi('miniapp:childInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(MiniChildInfo miniChildInfo)
    {
        startPage();
        List<MiniChildInfo> list = miniChildInfoService.selectMiniChildInfoList(miniChildInfo);
        return getDataTable(list);
    }

    /**
     * 导出孩子信息列表
     */
    @PreAuthorize("@ss.hasPermi('miniapp:childInfo:export')")
    @Log(title = "孩子信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MiniChildInfo miniChildInfo)
    {
        List<MiniChildInfo> list = miniChildInfoService.selectMiniChildInfoList(miniChildInfo);
        ExcelUtil<MiniChildInfo> util = new ExcelUtil<MiniChildInfo>(MiniChildInfo.class);
        util.exportExcel(response, list, "孩子信息数据");
    }

    /**
     * 获取孩子信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('miniapp:childInfo:query')")
    @GetMapping(value = "/{childId}")
    public AjaxResult getInfo(@PathVariable("childId") Long childId)
    {
        return success(miniChildInfoService.selectMiniChildInfoByChildId(childId));
    }

    /**
     * 新增孩子信息
     */
    @PreAuthorize("@ss.hasPermi('miniapp:childInfo:add')")
    @Log(title = "孩子信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MiniChildInfo miniChildInfo)
    {
        return toAjax((int) miniChildInfoService.insertMiniChildInfo(miniChildInfo));
    }

    /**
     * 修改孩子信息
     */
    @PreAuthorize("@ss.hasPermi('miniapp:childInfo:edit')")
    @Log(title = "孩子信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MiniChildInfo miniChildInfo)
    {
        return toAjax(miniChildInfoService.updateMiniChildInfo(miniChildInfo));
    }

    /**
     * 删除孩子信息
     */
    @PreAuthorize("@ss.hasPermi('miniapp:childInfo:remove')")
    @Log(title = "孩子信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{childIds}")
    public AjaxResult remove(@PathVariable Long[] childIds)
    {
        return toAjax(miniChildInfoService.deleteMiniChildInfoByChildIds(childIds));
    }
}
